﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;

namespace Entity
{
    public class DETAI
    {
        DataBaseAccess dataBaseAccess = new DataBaseAccess();


        private String MADT, TENDT, MAGV, LOAIDT;
        private int HOCKI, NAMHOC, SOTIETCHUAN;

        public String maDT
        {
            get { return MADT; }
            set { MADT = value; }
        }

        public String tenDT
        {
            get { return TENDT; }
            set { TENDT = value; }
        }

        public String maGV
        {
            get { return MAGV; }
            set { MAGV = value; }
        }
        public String loaiDT
        {
            get { return LOAIDT; }
            set { LOAIDT = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int hocki
        {
            get { return HOCKI; }
            set { HOCKI = value; }
        }

        public int namhoc
        {
            get { return NAMHOC; }
            set { NAMHOC = value; }
        }

        public int sotietchuan
        {
            get { return SOTIETCHUAN; }
            set { SOTIETCHUAN = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        public void hienthi_DeTai(DataGridView dtgDeTai)
        {
            String excuteString = "SELECT * FROM DETAI";
            DataTable dataTable = new DataTable();
            dataTable = dataBaseAccess.getDataTable(excuteString);
            dtgDeTai.DataSource = dataTable;
        }

        public void xoa_DeTai(String madetai)
        {
            String excuteString = "DELETE FROM DETAI WHERE MADT='" + madetai + "';";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void them_DeTai(DETAI detai)
        {
            String excuteString = "INSERT INTO DETAI VALUES('" + detai.maDT +"','" 
                                                               + detai.tenDT + "','"
                                                               + detai.maGV + "','"
                                                               + detai.loaiDT + "',"
                                                               + detai.hocki + ","
                                                               + detai.namhoc + "," 
                                                               + detai.sotietchuan +")";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void sua_DeTai(DETAI detai)
        {
            String excuteString = "UPDATE DETAI SET TENDT='" + detai.tenDT +
                                                  "',MAGV = '" + detai.maGV +
                                                  "', LOAIDT ='" + detai.loaiDT +
                                                  "', HOCKI =" + detai.hocki +
                                                  ", NAMHOC =" + detai.namhoc +
                                                  ",SOTIETCHUAN =" + detai.sotietchuan +
                                                  " WHERE MADT='" + detai.maDT + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }


    }





}
